// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

int n;

const int M = 15;
vector<LL> dat[11];

LL p3[M];

void doit(int n) {
    vector<LL> &a = dat[n];
    // static int b[M];

    for (int st=1; st<10; ++st) {
        int lim = p3[n-1];
        for (int mask=0; mask<lim; ++mask) {
            int cur = st, tmask = mask;
            LL x = st;
            bool suc = true;
            for (int j=0; j<n-1; ++j) {
                int now = tmask % 3;
                if (now == 0)
                    cur -= 1;
                else if (now == 2)
                    cur += 1;
                if (cur < 0 || cur > 9) {
                    suc = false;
                    break;
                }
                tmask /= 3;
                x = x * 10 + cur;
            }
            if (suc)
                a.push_back(x);
        }
    }
    sort(a.begin(), a.end());
}
vector<LL> tot;
int main(int argc, char const *argv[]) {
    // code

    p3[0] = 1;
    for (int i=1; i<M; ++i)
        p3[i] = p3[i-1] * 3;

    for (int i=1; i<11; ++i) {
        doit(i);
        for (LL x : dat[i])
            tot.push_back(x);
    }

    int n;
    cin >> n;
    cout << tot[n-1] << endl;
    return 0;
}
